package com.atguigu.tms.mock.service.impl;

import com.atguigu.tms.mock.bean.OrderOrgBound;
import com.atguigu.tms.mock.bean.TransportTask;
import com.atguigu.tms.mock.bean.TransportTaskDetail;
import com.atguigu.tms.mock.constant.TmsConstant;
import com.atguigu.tms.mock.mapper.OrderOrgBoundMapper;
import com.atguigu.tms.mock.service.OrderOrgBoundService;
import com.atguigu.tms.mock.service.adv.impl.AdvServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangchen
 * @since 2022-06-17
 */
@Service
public class OrderOrgBoundServiceImpl extends AdvServiceImpl<OrderOrgBoundMapper, OrderOrgBound> implements OrderOrgBoundService {


    @Override
    public List<OrderOrgBound> getOrderOrgBoundList(String boundStatus) {
        List<OrderOrgBound> orderOrgBoundList = this.list(new QueryWrapper<OrderOrgBound>().eq("status",boundStatus).orderByAsc("inbound_time"));
        return orderOrgBoundList;
    }


    public  List<OrderOrgBound>   initOrderOrgBoundList(  TransportTask transportTask){

        List<OrderOrgBound> orderOrgBoundList=new ArrayList<>();
        List<TransportTaskDetail> transportTaskDetailList = transportTask.getTransportTaskDetailList();

        for (TransportTaskDetail transportTaskDetail : transportTaskDetailList) {

            //入站
            OrderOrgBound orderOrgBound=new OrderOrgBound();
            orderOrgBound.setOrderId(transportTaskDetail.getOrderId());
            orderOrgBound.setOrgId(transportTask.getEndOrgId());
            orderOrgBound.setInboundEmpId(transportTask.getDriver1EmpId());
            orderOrgBound.setInboundTime(transportTask.getActualEndTime());
            orderOrgBound.setStatus(TmsConstant.BOUND_STATUS_IN);
            orderOrgBound.setCreateTime(transportTask.getActualEndTime());
            orderOrgBound.setIsDeleted("0");
            orderOrgBoundList.add(orderOrgBound);
        }

        saveOrUpdateBatch(orderOrgBoundList,1000,true);

        return orderOrgBoundList;
    }


}
